import { request } from '../../../../services/request';

// IPQC详情接口参数类型              
export interface IPQCBodyListParams {
    ipqc_num: string;
}

// IPQC详情列表项类型
export interface IPQCBodyItem {
    id: string;
    create_time: string;
    update_time: string;
    tenant_id: string;
    delete_flag: boolean;
    header_id: string;
    ipqc_num: string;
    state: number;
    check_state: number;
    quantity: number;
    sample_quantity: number;
    qualified_quantity: number;
    unqualified_quantity: number;
    fatal_quantity: number;
    fatal_rate: number;
    rework_quantity: number;
    rework_rate: number;
    accept_quantity: number;
    accept_rate: number;
    product_id: string;
    product_short_name: string;
    product_name: string;
    product_model: string;
    product_specs: string;
    product_encode: string;
    product_bar_code: string;
    product_link: string;
    supplier_id: string;
    supplier_name: string;
    batch_num: string;
    odd_id: string;
    odd_num: string;
    asn_unload_id: string;
    asn_time: string;
    qc_time: string;
    qc_date: string;
    qc_month: string;
    qc_week: string;
    qc_year: string;
    product_list: any[];
    prj_name?: string;
    unit_kk?: string;
    test_standard?: string;
}

// IPQC详情响应类型
export interface IPQCBodyListResponse {
    code: number;
    msg: string;
    data: IPQCBodyItem[];
}

// 获取IPQC详情列表
export const getIPQCBodyList = async (params: IPQCBodyListParams): Promise<IPQCBodyListResponse> => {
    console.log('=== IPQC详情接口请求数据 ===');
    console.log('请求参数:', params);
    console.log('======================');

    try {
        const response = await request('app/qms/getIPQCBodyList', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('=== IPQC详情接口返回数据 ===');
        console.log('响应状态:', response.code);
        console.log('响应消息:', response.msg);
        console.log('响应数据:', response);
        console.log('======================');

        return response;
    } catch (error) {
        console.error('=== IPQC详情接口调用失败 ===');
        console.error('错误信息:', error);
        console.error('======================');
        throw error;
    }
};

// 执行IPQC
export const execIPQC = async (params: any[]): Promise<any> => {
    console.log('=== IPQC执行接口请求数据 ===');
    console.log('请求参数:', params);
    console.log('======================');
    try {
        const response = await request('app/qms/execIPQC', {
            method: 'POST',
            body: JSON.stringify(params),
        });
        console.log('=== IPQC执行接口返回数据 ===');
        console.log('响应数据:', response);
        console.log('======================');
        return response;
    } catch (error) {
        console.error('=== IPQC执行接口调用失败 ===');
        console.error('错误信息:', error);
        console.error('======================');
        throw error;
    }
}; 